package swu.edu.cn.javaee.controller;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import swu.edu.cn.javaee.entity.Merchant;
import swu.edu.cn.javaee.entity.MerchantInfo;
import swu.edu.cn.javaee.entity.MerchantInfoP;
import swu.edu.cn.javaee.service.MerchantService;

@Controller
@CrossOrigin(origins = "*")
public class MerchantController {
    @Resource
    private MerchantService merchantService;


    //增加商户请求
    @RequestMapping("/saveMerchant")
    @ResponseBody
    public String saveMerchant(Merchant merchant){
        String result=merchantService.saveMerchant(merchant);
        return result;
    }

    //查询商户请求
    @RequestMapping("/queryMerchant")
    @ResponseBody
    public MerchantInfo queryMerchant(String userUid){
        MerchantInfo merchantInfo=merchantService.queryMerchant(userUid);
        return merchantInfo;
    }

    //修改商户请求
    @RequestMapping("/updateMerchant")
    @ResponseBody
    public String updateMerchant(Merchant merchant){
        String result=merchantService.updateMerchant(merchant);
        return result;
    }

    //注销商户请求
    @RequestMapping("/deleteMerchant")
    @ResponseBody
    public String deleteMerchant(@RequestParam(value = "cid") String cid){
        String result=merchantService.deleteMerchant(cid);
        return result;
    }

    //后台删除商户
    @RequestMapping("/deleteMerchantP")
    @ResponseBody
    public MerchantInfoP deleteMerchantP(@RequestParam(value = "cid") String cid){
        MerchantInfoP result=merchantService.deleteMerchantP(cid);
        return result;
    }
    //查询所有商户请求
    @RequestMapping("/merchantAllInformation")
    @ResponseBody
    public MerchantInfoP merchantAllInformation(){
        MerchantInfoP merchantInfoP=merchantService.queryList();
        return merchantInfoP;
    }
    //分页查询
    @RequestMapping("/merchantLimitInformation")
    @ResponseBody
    public MerchantInfoP merchantLimitInformation(@RequestParam(required = true,value = "page") String page,
                                                  @RequestParam(required = true,value = "limit")String limit){
        MerchantInfoP merchantInfoP = merchantService.queryListLimit(page,limit);
        return merchantInfoP;
    }

    /**
     * 后台给根据用户uid查询用户信息
     * */
    @RequestMapping("/queryMerchantP")
    @ResponseBody
    public MerchantInfoP queryMerchantP(String userUid){
        MerchantInfoP merchantInfoP=merchantService.queryMerchantP(userUid);
        return merchantInfoP;
    }
}
